package com.ac.cv.client;

import java.util.List;

import com.ac.cv.client.menu.ClickableLabel;
import com.ac.cv.client.menu.MenuItem;
import com.ac.cv.client.menu.MenuItemLabel;
import com.ac.cv.client.menu.MenuMainLabel;
import com.ac.cv.client.service.MenuItemDataClient;
import com.ac.cv.client.service.MenuMainItemDataClient;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.Tree;

/**
 * Builder class for the page's menu
 * 
 * @author CHATELLIER
 * 
 */
public class Menu {

	public static Tree buildMenu(DeckPanel panel, List<MenuMainItemDataClient> menuData) {
		final Tree staticTree = new Tree();
		staticTree.addStyleName("menu");
		
		int menuItemCounter = 0;
		for (MenuMainItemDataClient mainItem : menuData) {
			MenuItem menuItem = new MenuItem();
			ClickableLabel authorLabel = new MenuMainLabel(menuItem);
			authorLabel.setText(mainItem.getName());
			authorLabel.setTitle(mainItem.getTitle());
			menuItem.setLabel(authorLabel);
			for (MenuItemDataClient item : mainItem.getItemList()) {
				MenuItemLabel menuItemLabel = new MenuItemLabel(
						menuItemCounter, panel);
				menuItemLabel.setText(item.getName());
				menuItemLabel.setTitle(item.getTitle());
				menuItemCounter++;
				menuItem.addChildLabel(menuItemLabel);
			}
			staticTree.addItem(menuItem);

		}
		staticTree.setAnimationEnabled(true);
		staticTree.addStyleName("sidebarSize");
		return staticTree;
	}

	
}